<docs>
  ## 编辑个人基本信息
</docs>
<template>
  <div class="wrap">
    <co-form :model="data" :rules="rules" ref="form" label="个人基本信息">
      <!-- <co-input prop="nl" label="年龄" type="tel"
        v-model="data.nl" placeholder="请输入年龄"></co-input> -->
      <co-select prop="mz" label="民族" v-model="data.mz" :list="codeTable.cdg_nation"></co-select>
      <co-select prop="rylb" label="人员类别" v-model="data.rylb"
        :list="codeTable.zyjs_d_rylb"></co-select>
      <co-select prop="hjxz" label="户籍性质" v-model="data.hjxz"
        :list="codeTable.cdl_rprtype"></co-select>
      <co-level-picker label="户籍地行政区划" prop="hjdxzqh" v-model="data.hjdxzqh"
        :name="data.hjdxzqh_xs"
        table-name="cdg_regioncode"></co-level-picker>
      <co-input prop="hkszd" label="户口所在地"
        v-model="data.hkszd" placeholder="请输入户口所在地"></co-input>
      <co-level-picker label="居住地行政区划" prop="jzdxzqh" v-model="data.jzdxzqh"
        :name="data.jzdxzqh_xs"
        table-name="cdg_regioncode"></co-level-picker>
      <co-input prop="jzddz" label="居住地址"
        v-model="data.jzdz" placeholder="请输入居住地址"></co-input>
      <co-select prop="whcd" label="文化程度" v-model="data.whcd"
        :list="codeTable.zyjsww_d_whcd"></co-select>

      <co-select prop="zysl" label="视力（左）" v-model="data.zysl"
        :list="codeTable.zyjs_d_slb"></co-select>
      <co-select prop="yysl" label="视力（右）" v-model="data.yysl"
        :list="codeTable.zyjs_d_slb"></co-select>
      <co-select prop="jkzk" label="健康状况" v-model="data.jkzk"
        :list="codeTable.cdg_healthstate"></co-select>
      <co-select prop="zzmm" label="政治面貌" v-model="data.zzmm"
        :list="codeTable.cdg_politicsaspect"></co-select>
      <!-- <co-select prop="hyzk" label="婚姻状况" v-model="data.hyzk"
        :list="codeTable.cdg_marriage"></co-select> -->
      <co-input prop="sg" label="身高"
        v-model="data.sg" placeholder="请输入身高"></co-input>
      <co-input prop="tz" label="体重"
        v-model="data.tz" placeholder="请输入体重"></co-input>
      <co-input prop="sxzy" label="所学专业"
        v-model="data.sxzy" placeholder="请输入所学专业"></co-input>
      <co-input prop="byyx" label="毕业院校"
        v-model="data.byyx" placeholder="请输入毕业院校"></co-input>
      <data-picker prop="bysj" label="毕业时间"
        v-model="data.bysj"></data-picker>
      <!-- <co-input prop="bysj" label="毕业时间" type="tel"
        v-model="data.bysj" placeholder="请输入毕业时间"></co-input> -->
      <co-select prop="byyxlb" label="毕业院校类别" v-model="data.byyxlb"
        :list="codeTable.zyjs_d_byyxlb"></co-select>
      <co-input prop="dexl" label="第二学历"
        v-model="data.dexl" placeholder="请输入第二学历"></co-input>
      <co-input prop="lxr" label="联系人"
        v-model="data.lxr" placeholder="请输入联系人"></co-input>
      <co-input prop="lxrdh" label="联系人电话" type="tel"
        v-model="data.lxrdh" placeholder="请输入联系人电话"></co-input>
      <co-input prop="qtsm" label="其他说明"
        v-model="data.qtsm" placeholder="请输入其他说明"></co-input>


      <co-input prop="gddh" label="固定电话" type="tel"
        v-model="data.gddh" placeholder="请输入固定电话"></co-input>
      <co-input prop="sj" label="手机号码" type="tel"
        v-model="data.sj" placeholder="请输入手机号码"></co-input>
      <co-input prop="email" label="邮箱" type="email"
       v-model="data.email" placeholder="请输入邮箱"></co-input>

    </co-form>
    <div class="btn-wrap">
      <button class="weui-btn weui-btn_primary" @click.prevent="save" type="button">保存</button>
      <button class="weui-btn weui-btn_default" @click="backBase" type="button">返回</button>
    </div>

  </div>
</template>
<script>
import coForm from 'base/form/form';
import coInput from 'base/form/input';
import coSelect from 'base/form/select';
import { validator } from 'common/js/valid';
import coLevelPicker from 'base/form/levelPicker';
import dataPicker from 'base/form/dataPicker';

export default {
  name: 'editBaseInfo',
  components: { coForm, coInput, coSelect, coLevelPicker, dataPicker },
  data() {
    return {
      data: {
        grqzid: '',
        mz: '', // 民族
        // nl: '', // 年龄
        sj: '', // 手机号
        gddh: '', // 固定电话
        email: '',
        hjxz: '', // 户籍性质
        rylb: '', // 人员类别
        zysl: '', // 视力（左）
        yysl: '', // 视力（右）
        hjdxzqh: '', // 户籍地行政区划
        whcd: '', // 文化程度
        jzdxzqh: '', // 居住地行政区划
        jzddz: '', // 居住地地址
        jkzk: '',  // 健康状况
        hkszd: '',  // 户口所在地
        zzmm: '',  // 政治面貌
        // hyzk: '',  // 婚姻状况"
        sg: '',  // 身高"
        tz: '',  // 体重"
        sxzy: '',  // 所学专业
        byyx: '',  // 毕业院校
        bysj: '',  // 毕业时间
        byyxlb: '',  // 毕业院校类别
        dexl: '',  // 第二学历
        lxr: '',  // 联系人
        lxrdh: '',  // 联系人电话"
        qtsm: '',  // 其他说明"
       },
      rules: {
        // nl: validator('3,"full","年龄",false'), // 年龄
        mz: validator('2,"full","民族",false'), // 民族
        sj: validator('11,"sjh","手机",false'), // 手机号
        gddh: validator('32,"full","固定电话",true'), // 固定电话
        email: validator('48,email,"邮箱",true'), // 邮箱
        hjxz: validator('2,"full","户籍性质",false'), // 户籍性质
        rylb: validator('2,"full","人员类别",false'), // 人员类别
        zysl: validator('2,"full","视力（左）",true'), // 视力（左）
        yysl: validator('2,"full","视力（右）",true'), // 视力（右）
        hjdxzqh: validator('12,"full","户籍地行政区划（行政区划）",false'),
        hkszd: validator('128,"normal","户口所在地",false'),
        whcd: validator('2,"full","文化程度",false'), // 文化程度
        jzdxzqh: validator('12,"full","居住地行政区划（行政区划）",false'),
        jzddz: validator('128,"full","居住地",false'),
        jkzk:  validator('1,"full","健康状况",false'),  // 健康状况
        zzmm:  validator('2,"full","政治面貌",true'),  // 政治面貌
        // hyzk:  validator('1,"full","婚姻状况",true'),  // 婚姻状况"
        sg:  validator('3,"full","身高",true'),  // 身高"
        tz:  validator('3,"full","体重",true'),  // 体重"
        sxzy:  validator('128,"full","所学专业",false'),  // 所学专业
        byyx:  validator('64,"full","毕业院校",true'),  // 毕业院校
        bysj:  validator('8,"full","毕业时间",true'),  // 毕业时间
        byyxlb:  validator('2,"full","毕业院校类别",true'),  // 毕业院校类别
        dexl:  validator('30,"full","第二学历",true'),  // 第二学历
        lxr:  validator('32,"full","联系人",true'),  // 联系人
        lxrdh:  validator('32,"normal","联系人电话",true'),  // 联系人电话"
        qtsm:  validator('128,"full","其他说明",true'),  // 其他说明"
      },
      codeTable: {
        cdg_nation: [], // 民族
        zyjs_d_rylb: [], // 人员类别
        cdl_rprtype: [], // 户籍性质
        zyjs_d_slb: [], // 视力
        cdg_healthstate: [], // 健康状况
        zyjsww_d_whcd: [], // 文化程度
        cdg_politicsaspect: [], // 政治面貌
        // cdg_marriage: [], // 婚姻状况
        zyjs_d_byyxlb: [], // 毕业院校类别
      },
      hjdxzqh_xs: '',
      jzdxzqh_xs: ''
    };
  },
  methods: {
    save() {
      this.$refs.form.validate(() => {
        this.POST_save();
      });
    },
    /* 获取代码表 */
    GET_codeTable() {
      const arrTableName = Object.keys(this.codeTable);
      this.$http.get('/dmbgl/dmblbCx', {
        params: {
          table_name: arrTableName.join()
        }
      }).then((res) => {
        this.getCodeTabled = true;
        const data = res.returnData.dmblb;
        arrTableName.forEach(item => {
          this.codeTable[item] = data[item];
        });
      });
    },
    /* 保存基本信息修改 */
    POST_save() {
      this.$loading = true;
      this.data.ywcz = 2;
      this.$http.post('/grgl/jbxxBc', this.data).then(res => {
        const resData = res.returnData;
        this.$alert(resData.message, () => {
          const code = +resData.executeResult;
          if (code) {
            this.backBase();
          }
        });
      }).finally(() => {
        this.$loading = false;
      });
    },
    /*  查询基本信息 */
    GET_getInfo() {
      this.$http.get('/grgl/grxqCx').then(res => {
        const resData = res.returnData;
        this.data = resData.jbxx;
      }).finally(() => {
        this.$loading = false;
      });
    },
    /* 返回基础信息 */
    backBase() {
      this.$router.go(-1);
    }
  },
  created() {
    // 获取代码表
    this.getCodeTabled = false;
    this.GET_codeTable();
    this.GET_getInfo();
    // 赋值
    const { data } = this.$route.params;
    if (!data) return;
    Object.keys(this.data).forEach(item => {
      this.data[item] = data[item];
    });
    // 行政区划显示
    this.hjdxzqh_xs = data.hjdxzqh_xs;
    this.jzdxzqh_xs = data.jzdxzqh_xs;
    // 隐藏home按钮
    this.$store.commit('SET_VISIBLE_ALL', false);
  }
};
</script>
<style scoped lang="scss">
@import '~common/scss/var.scss';
.wrap {
  background: $color-bg;
  .btn-wrap {
    display: flex;
    .weui-btn {
      margin: $margin-base auto;
      flex: 0 1 47%;
    }
  }
}
</style>
